package com.atguigu.gmall.list.controller.api;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/***
 * 商品搜索的控制层
 */
@RestController
@RequestMapping("/api/search")
public class ApiSearchController {

    @Autowired
    private SearchService service;

    /**
     * 搜索商品
     * @return
     */
    @GetMapping
    public Map search(@RequestParam Map<String,Object> searchParams){
        //1 校验参数
        if(searchParams == null){
            throw new GmallException("搜索参数有误",null);
        }

        //2 调用业务层的方法
        Map<String,Object> result = service.search(searchParams);

        //3 返回数据
        return result;
    }
}
